/*
 * $Id: ErrorMessageResolver.java,v 1.9 2009/07/21 17:10:57 afaichun Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.onwatch.resolver;

import java.util.Map;

import com.ge.healthcare.autosc.common.ASCLogger;
import com.ge.healthcare.autosc.onwatch.xml.tag.TaskListTag;
import com.ge.healthcare.autosc.onwatch.xml.tag.TaskTag;
import com.thoughtworks.xstream.XStream;
/**
 * This class resolves error from object model into XML string.
 * @author 212042946
 *
 */
public class ErrorMessageResolver implements IXmlMessageResolver {

	/**
	 * Marshal from model to Xml
	 */
	public String marshalToXml(Map model) throws Exception {
		String methodName = "marshalToXml";
		ASCLogger.debug(this.getClass(), methodName, "Entered " + methodName);
		String errorStr = (String)model.get("error");
		// Identify the system
		Long taskId = (Long)model.get("taskId");
		String systemId = (String)model.get("systemId");
		String iipVersion = (String)model.get("iipVersion");
		if(errorStr == null) {
			ASCLogger.error(this.getClass(), methodName,
					"ErrorMessageResolver is called without error description.");
			errorStr = "Internal System Error. Please contact system administrator";
					
		}
		
		TaskListTag taskList = new TaskListTag(systemId, iipVersion);
		TaskTag taskTag = new TaskTag(taskId);
		taskTag.setFailureStatus(errorStr);
		taskList.addTask(taskTag);
		
		XStream xStream = new XStream();
		xStream.processAnnotations(TaskListTag.class);
		xStream.processAnnotations(TaskTag.class);
		return xStream.toXML(taskList);
	}
}
